
<template>
    <div class="normal-container">
        <div v-if="!showAddDetail">
            <div class="normal-text">{{ $route.name }}</div>
            <div class="content-main">
                <section>
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="类别">
                            <el-select v-model="formInline.type" placeholder="请选择" clearable>
                                <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.name">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="名称">
                            <el-input v-model="formInline.name" placeholder="请输入名称" clearable></el-input>
                        </el-form-item>
                        <el-form-item label="编号">
                            <el-input v-model="formInline.code" placeholder="请输入编号" clearable></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" class="noraml-btn" @click="getList(true)">查询</el-button>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="noraml-btn" @click="Export"
                                v-loading.fullscreen.lock="fullscreenLoading">导出EXCEL</el-button>
                        </el-form-item>
                    </el-form>
                </section>
                <section>
                    <el-table v-loading="loading" ref="tableMain" :header-cell-style="{
                        'text-align': 'center',
                        background: '#F6F7FB',
                        color: '#4B4B4B',
                        fontSize: '13px',
                    }" :cell-style="{ 'text-align': 'center' }" :data="tableData" style="width: 100%"
                        :max-height="tableHeight">
                        <el-table-column type="index" label="序号" width="50"></el-table-column>
                        <el-table-column prop="type" label="类别"></el-table-column>
                        <el-table-column prop="code" label="编号"></el-table-column>
                        <el-table-column prop="name" label="名称"></el-table-column>
                        <el-table-column prop="norm" label="规格"></el-table-column>
                        <el-table-column prop="unit" label="单位"></el-table-column>
                        <el-table-column prop="manufacturer" label="厂家"></el-table-column>
                        <el-table-column prop="remark" label="备注"></el-table-column>
                        <el-table-column label="数量">
                            <template slot-scope="scope">
                                <span :style="{'color': scope.row.num < scope.row.cnt ? 'red' : ''}">{{scope.row.num}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="cnt" label="安全库存"></el-table-column>
                    </el-table>
                </section>
                <section style="text-align:center;padding-top:20px">
                    <el-pagination background @current-change="handleCurrentChange" :page-size="pageForm.size"
                        :current-page="pageForm.current" layout="prev, pager, next" :total="total">
                    </el-pagination>
                </section>
            </div>
        </div>
      
    </div>
</template>
  
<script>

export default {

    data() {
        return {
            showAddDetail: false,
            showDetailPage: false,
            showDetail: false,
            total: 0,
            loading: false,
            formInline: {
                type: '',
                name: '',
                code: '',
            },
            pageForm: {
                current: 1,
                size: 20
            },
            tableData: [],
            id: "",
            tableHeight: 500,
            options: [],
            fullscreenLoading:false
        }
    },
    mounted() {
        this.getDept();
        this.$nextTick(res => {
            const tableHeight = document.documentElement.clientHeight;
            const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 115;
            this.tableHeight = tableHeight - topHeight;
        })
        this.getList();
    },
    computed: {
        listenHeight() {
            return this.$store.state.user.heightSize
        }
    },
    watch: {
        listenHeight(val) {
            const tableHeight = document.documentElement.clientHeight;
            const topHeight = this.$refs.tableMain.$el.getBoundingClientRect().top + 115;
            this.tableHeight = tableHeight - topHeight;
        }
    },
    methods: {
        Export() {
            this.fullscreenLoading = true;
            this.methExportExcel("post", "/spar/stock-record/expStock", this.formInline, "库存管理").then((res) => {
                this.fullscreenLoading = res;
            });

        },
        getDept() {
            return new Promise(resolve => {
                this.$baseRequestGet('/sys/dict/getList/4', {}, 'get').then(res => {
                    this.options = res.data;
                    resolve();
                })
            })

        },
        clickDelete(item) {
            this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            })
        },
        clickDetail(item) {
            this.id = item.id;
            this.showDetail = true;
        },
        closeDetail(isFresh) {
            if (isFresh) this.getList();
            this.showDetail = false;
            this.id = '';
        },
        getList(isClear) {
            this.loading = true;
            if (isClear) this.pageForm.current = 1; // 点击搜索
            this.$baseRequest("/spar/stock-record/stockPageList", this.formInline, this.pageForm, "post").then(
                (res) => {
                    this.tableData = res.data.records;
                    this.total = Number(res.data.totalRow);
                    this.loading = false;
                }
            ).catch(res => {
                this.loading = false;
            })
        },
        handleCurrentChange(val) {
            this.pageForm.current = val;
            this.getList();
        },
    }
}
</script>
  
<style lang="scss" scoped>
.content-main {
    border: 1px solid #DFE2E8;
    padding: 30px;
    background-color: #fff;
}
.is-useing {
    color: #00B42A;
    position: relative;
}

.is-useing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #00B42A;
}

.is-no-seing {
    color: #FF7D00;
    position: relative;

}

.is-no-seing::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 40%;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background-color: #FF7D00;
}
</style>
  